//
//  AnonymityObjectViewController.m
//  Effective Objective-C 2.0
//
//  Created by 周成龙 on 2017/11/17.
//  Copyright © 2017年 周成龙. All rights reserved.
//

#import "AnonymityObjectViewController.h"

@protocol AnonymityObjectDelegate
- (void)connect;
- (void)disconnect;
- (BOOL)isConnected;
- (NSArray *)performQery:(NSString *)query;
@end

@interface AnonymityObject : NSObject<AnonymityObjectDelegate>

@end
@implementation AnonymityObject
- (void)connect {
    NSLog(@"哈哈哈哈");
}
- (void)disconnect {
    NSLog(@"12km");
}
- (BOOL)isConnected {
    return YES;
}
- (NSArray *)performQery:(NSString *)query {
    return @[@"1", @"2", @"3"];
}
@end

@interface AnonymityObjectManager : NSObject
+ (id)shareInstance;
- (id<AnonymityObjectDelegate>)connectionWithIdentifier:(NSString *)identyfier;
@end

@implementation AnonymityObjectManager
static AnonymityObjectManager *_instance;
+ (id)shareInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[AnonymityObjectManager alloc] init];
    });
    return _instance;
}
- (id<AnonymityObjectDelegate>)connectionWithIdentifier:(NSString *)identyfier {
    AnonymityObject *obj = [[AnonymityObject alloc] init];
    return obj;
}
@end



@interface AnonymityObjectViewController ()

@end

@implementation AnonymityObjectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    id<AnonymityObjectDelegate> obj = [[AnonymityObjectManager shareInstance] connectionWithIdentifier:@"123"];
    [obj connect];
    [obj disconnect];
    NSLog(@"%zd", [obj isConnected]);
    NSLog(@"%@", [obj performQery:@"111"]);
}


@end
